package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.pojo.Orders;
import com.itheima.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 林晓伟
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrdersController {
    @Resource
    private OrdersService ordersService;

    /**
     * H23-订单分页查询
     * @param beginTime 开始时间
     * @param endTime 结束时间
     * @param number id
     * @param page 页数
     * @param pageSize 每页条数
     */
    @GetMapping("/page")
    public R s(@RequestParam(value="beginTime",required=false)String beginTime,
               @RequestParam(value="endTime",required=false)String endTime,
               @RequestParam(value="number",required=false)String number,
               @RequestParam(value="page",required=false)Integer page,
               @RequestParam(value="pageSize",required=false)Integer pageSize){
        Page<Orders> select = ordersService.select(page, pageSize, beginTime, endTime, number);
        return R.success(select);
    }

    /**
     * H24-修改订单状态
     */
    @PutMapping
    public R jk(@RequestBody Orders orders){
        Integer jk = ordersService.jk(orders);
        if (jk != 0){
            return R.success("");
        }
        return R.error("");
    }
}
